package com.epi.one.basic.generic;

/**
 * @author dxy
 * @version 1.0
 */
public class MyArray<E extends Number> {
    private E[] eData;
    private Object[] objData;

    public MyArray(E... nums) {
        this.eData = nums;
        this.objData = nums;
    }

    public E printE() {
        System.out.println("Type  eData= " + eData.getClass());
        System.out.println("Type  eData[0]  = " + eData[0].getClass());
        System.out.println("Type  eData[1]  = " + eData[1].getClass());
        return eData[0]; // 编译器知道是 E 类型
    }

    public E printO() {
        System.out.println("Type  objData = " + objData.getClass());
        System.out.println("Type  objData[0] = " + objData[0].getClass());
        System.out.println("Type  objData[1] = " + objData[1].getClass());
        return (E) objData[0]; // 显式转换
    }

    public E getE(int i, boolean silent) {
        System.out.println("Type  eData[" + i + "] = " + eData[i].getClass());
        return silent ? null : eData[i];
    }

    public E getO(int i, boolean silent) {
        System.out.println("Type  objData[" + i + "] = " + objData[i].getClass());
        return silent ? null : (E)objData[i];
    }
}

